﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace SilverLightStreamingInterface
{
    class Settings
    {
        public static string[] ValidFileTypes
        {
            get {return new string[] {"ttf", "odttf", "js", "dll", "xaml", "xml", "zip", "xap", "wma", "wmv", "mp3", "gif",
            "jpeg", "png", "txt", "sdx", "bin", "jpg"};}
        }

        static Dictionary<string, string> _mime = null;
        internal static string MimeType(string p)
        {
            if (_mime == null)
            {
                _mime = new Dictionary<string, string>();
                string[] vtypes = ValidFileTypes;
                string[] mtypes = new string[] {"application/octet-stream", "application/octet-stream", "application/x-javascript", "application/x-msdownload", "application/xaml+xml", "application/xml", "application/x-zip-compressed", "application/x-sliverlight-app", "audio/x-ms-wma", "audio/x-ms-wmv", "audio/mpeg", "image/gif", "image/jpeg", "image/png", "text/plain", "text/plain", "text/plain", "image/jpeg" };
                for (int i = 0; i < vtypes.Length; i++)
                {
                    _mime[vtypes[i]] = mtypes[i];
                }
            }
            return _mime[p];
        }

        /// <summary>
        /// Gets the template file that contains the HTML for viewing this guy from the SL streaming service.
        /// </summary>
        static public FileInfo TemplateHTML
        {
            get
            {
                /// Development Code is BAD... but...
                string devLocation = @"..\..\..\conference.html";
                if (File.Exists(devLocation))
                {
                    return new FileInfo(devLocation);
                }

                /// Perhaps next to the current executable (from an install)?
                string reallocation = Assembly.GetCallingAssembly().Location;
                reallocation = reallocation.Substring(0, reallocation.LastIndexOf('\\'));
                reallocation += "\\SLStreamTemplate\\conference.html";
                if (!File.Exists(reallocation))
                {
                    throw new SilverLightStreamException("Could not find the template files for the SilverLight control. Expected them in SLStreamTemplate");
                }
                return new FileInfo(reallocation);
            }
        }
    }
}
